<?php namespace Common\Model; 
use Hdphp\Model\Model;
//前台IndentList模型
class IndentList extends Model{
	//指定Indent表名
	protected $table = 'indent_list';
	//执行添加
	public function store(){
		//判断用户是否直接购买的商品(是)
		if(isset($_SESSION['shopbuy'])){
			//购买的商品存在$_SESSION['shopbuy']里 
			$goodsData = $_SESSION['shopbuy'];
		}else{
			//购买的商品存在$_SESSION['cart']里 
			$goodsData = Cart::getGoods();
		}
		//获取备注信息
		$explain = q('post.explain');
		//获取商品键名
		$goodsData_key = array_keys($goodsData);
		//组合数组	[商品键名=>备注信息]
		$explain_now = [];
		for($i=0;$i<count($explain);$i++)
		{		
			$explain_now[$goodsData_key[$i]] = $explain[$i];		
		}
		//遍历商品
		foreach($goodsData as $k=>$v){
			//查询货物列表
			$goodsListModel = new GoodsList;
			$lnumber = $goodsListModel->where('combine',$v['combine'])->pluck('lnumber');	
			//从	$_SESSION 中取出订单号
			$iid = q('post.iid');
			$data[$k] = [
				'quantity'   => $v['num'],        	//购买数量
				'subtotal'   => $v['total'],		//价格小计
				'ilnumber'   => $lnumber,		 	//货品货号
				'goods_gid'  => $v['id'],       	//商品id
				'indent_iid' => $iid,				//订单id
				'explain'    =>	$explain_now[$k]    //备注
			];	
			//添加数据
			$this->add($data[$k]);							
		}				
	}	
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	